<template>
    <rx-layout class="OsInstShowApplyInstList">
        <template #middle>
            <rx-fit v-model="fitSearch">
                <template #head>
                    <div style="display: flex;align-items: center;justify-content: space-between;">
                        <rx-list-title :title="i18n('list.applyManage','加入机构申请列表')"></rx-list-title>
                        <span class="search-btn" @click.stop="searchshow" @mousedown.stop><SearchOutlined/>{{
                                $ti18('rxList.leachBtn', '过滤')
                            }}</span>
                    </div>
                </template>
                <template #search>
                    <a-form :layout="colLayout">
                        <a-row :gutter="24">
                            <a-col :span="colSpan">
                                <a-form-item :label="i18n('form.applicant','申请人')">
                                    <a-input :placeholder="i18n('form.applicant','申请人','input')"
                                             v-model:value="urlConfig.queryParam.Q_FULLNAME__S_LK"/>
                                </a-form-item>
                            </a-col>
                        </a-row>
                    </a-form>
                    <div class="list-search-toolbar">
                        <a-button type="primary" @click="search">
                            <SearchOutlined/>
                            {{ $ti18('rxList.searchBtn', '查询') }}
                        </a-button>
                        <a-button style="margin-left: 4px" @click="resetSearch">
                            <RedoOutlined/>
                            {{ $ti18('rxList.resetBtn', '重置') }}
                        </a-button>
                    </div>
                </template>
                <template #middle>
                    <rx-grid ref="table"
                             :hasPage="true"
                             :urlConfig="urlConfig"
                             :selectConfig="selectConfig"
                             url="/api-user/user/org/osInst/applyInstData"
                             field="id"
                             :columns="columns"
                    >
                        <template #deliverUserName="{row}">
                            {{ row.deliverUserName }}({{ row.deliverUserNo }})
                        </template>
                        <template #receiptUserName="{row}">
                            {{ row.receiptUserName }}({{ row.receiptUserNo }})
                        </template>
                        <template #action="{ row }">
                            <RxGridAction :size="2">
                                <div v-if="row.applyStatus=='APPLY' " @click.stop="agree(row)">
                                    {{ i18n('list.agree', '同意') }}
                                </div>
                                <div v-if="row.applyStatus=='APPLY'" @click.stop="refuse(row)">
                                    {{ i18n('list.refuse', '拒绝') }}
                                </div>
                                <div v-if="row.applyStatus=='ENABLED'" @click.stop="updateUser(row,'DISABLED')">
                                    {{ i18n('list.disable', '禁用用户') }}
                                </div>
                                <div v-if="row.applyStatus=='DISABLED'" @click.stop="updateUser(row,'ENABLED')">
                                    {{ i18n('list.enable', '启用用户') }}
                                </div>
                                <div v-if="row.applyStatus=='REFUSE'" @click.stop="agree(row)">
                                    {{ i18n('list.reapprove', '重新同意') }}
                                </div>
                            </RxGridAction>
                        </template>
                    </rx-grid>
                </template>
            </rx-fit>
        </template>
    </rx-layout>
</template>

<script>
import OsInstApi from '@/common/api/user/osInst'
import {BaseList, RxLayout, RxGrid, RxFit, Util} from '@lowcode/jpaas-base-lib'
import OsInstApplyInstEdit from "./OsInstApplyInstEdit.vue";

export default {
    name: 'OsInstShowApplyInstList',
    components: {
        RxLayout,
        RxGrid,
        RxFit
    },
    mixins: [BaseList],
    data() {
        return {
            urlConfig: {
                ajaxType: 'post',
                contentType: 'json',
                queryParam: {},
                dataField: 'result.data',
                totalField: 'result.totalCount'
            },
            selectConfig: {
                type: 'checkbox',
            },
            // 表头
            columns: [
                {
                    title: this.i18n('form.applicant', '申请人'),
                    field: 'usFullName',
                    minWidth: 120
                },
                {
                    title: this.$ti18('rxForm.notes', '备注'),
                    field: 'applyNote',
                    minWidth: 120
                },
                {
                    title: this.$ti18('rxForm.createTime', '创建时间'),
                    field: 'createTime',
                    minWidth: 160,
                },
                {
                    title: this.$ti18('rxList.action', '操作'),
                    minWidth: 60,
                    field: 'action',
                    slots: {default: 'action'}
                },
            ]
        }
    },
    methods: {
        i18n(name, text, key) {
            return this.$ti18(name, text, "OsInstShowCanApply", key);
        },
        agree(record) {
            this.userDialog(record, "1");
        },
        refuse(record) {
            this.userDialog(record, "0");
        },
        updateUser(record, status) {
            var self = this;
            var tips = ""
            if (status == "DISABLED") {
                tips = this.i18n("msa.disableUser", "是否禁用用户？")
            } else if (status == "ENABLED") {
                tips = this.i18n("msa.enableUser", "是否启用用户？")
            }
            this.$confirm({
                title: this.$ti18('rxMsa.actionTips', '操作提示'),
                zIndex: 20000,
                okText: this.$ti18('rxForm.ackBtn', '确认'),
                cancelText: this.$ti18('rxForm.cancelBtn', '取消'),
                content: tips,
                onOk() {
                    OsInstApi.updateUserStatus(record.tenantId, record.userId, status).then(res => {
                        self.refreshGrid();
                    })
                },
                onCancel() {
                }
            })
        },
        userDialog(record, approvalType) {
            var self = this;
            var conf = {
                curVm: this,
                widthHeight: ['800px', '430px'],
                shade: true,
                data: {instId: record.id, approvalType: approvalType, tenantId: record.tenantId},
                component: OsInstApplyInstEdit,
                title: this.i18n('prop.applyJoin', '处理申请加入本机构人员')
            };
            Util.open(conf, function (action) {
                self.refreshGrid();
            });
        }
    }
}
</script>
<style scoped>
.OsInstShowApplyInstList {
    padding: 10px;
}
.OsInstShowApplyInstList ::v-deep(.rx-fit-search-middle){
    overflow: hidden;
}
</style>
